<template>
  <div class="app-container">
    <el-form
      ref="salaryInfoForm"
      :model="listQuery"
      label-position="right"
      label-width="140px"
      size="small"
    >
      <el-row>
        <el-col :span="8">
          <el-form-item
            label="工资月份："
            prop="工资月份"
          >
            <el-date-picker
              v-model="listQuery.salaryMonth"
              type="month"
              placeholder="选择月份"
              format="yyyy-MM"
              value-format="yyyy-MM"
              :clearable="false"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="工资卡开户银行："
            prop="工资卡开户银行"
          >
            <el-select
              v-model="listQuery.salaCardBank"
              class="filter-item"
              placeholder="--请选择--"
              clearable
            >
              <el-option
                v-for="item in agencyBankLists"
                :key="item.code"
                :label="item.name"
                :value="item.code"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-button
          v-if="false"
          type="primary"
          @click="handleFilter"
        >查询
        </el-button>
      </el-row>
    </el-form>
    <el-table
      v-loading="listLoading"
      max-height="450px"
      :data="list"
      style="width: 100%"
      fit
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
    >
      <template slot="empty">
        <tableEmpty />
      </template>
      <el-table-column
        type="index"
        label="序号"
        fixed
        width="50"
      />
      <el-table-column
        prop="单位名称"
        label="单位名称"
        fixed
        align="center"
        width="220"
      />
      <el-table-column
        label="应发合计"
        align="center"
        width="150"
      >
        <template slot-scope="{row}">
          <div class="right">
            <span> {{ Number(row.应发合计).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="在职人员工资"
        align="center"
      >
        <el-table-column
          label="应发工资"
          align="center"
          width="120"
        >
          <template slot-scope="{row}">
            <div class="right">
              <span> {{ Number(row.应发工资).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="扣款项"
          align="center"
        >
          <el-table-column
            align="center"
            label="个人所得税"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="right">
                <span> {{ Number(row.个人所得税).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="住房公积金"
            align="center"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="right">
                <span> {{ Number(row.住房公积金).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="医疗保险金"
            align="center"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="right">
                <span> {{ Number(row.医疗保险金).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="养老保险"
            align="center"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="right">
                <span> {{ Number(row.养老保险).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="职业年金"
            align="center"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="right">
                <span> {{ Number(row.职业年金).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="补扣工资"
            align="center"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="right">
                <span> {{ Number(row.补扣工资).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="扣款合计"
            align="center"
            width="120"
          >
            <template slot-scope="{row}">
              <div class="right">
                <span> {{ Number(row.扣款合计).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
              </div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="实发工资"
          align="center"
          width="120"
        >
          <template slot-scope="{row}">
            <div class="right">
              <span> {{ Number(row.实发工资).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
            </div>
          </template>
        </el-table-column>

      </el-table-column>
      <el-table-column
        label="离退休人员离退休费"
        align="center"
      >
        <el-table-column
          label="应发离退休费"
          align="center"
          width="120"
        >
          <template slot-scope="{row}">
            <div class="right">
              <span> {{ Number(row.应发离退休费).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
            </div>
          </template>
        </el-table-column>

        <el-table-column
          label="代扣款"
          align="center"
          width="120"
        >
          <template slot-scope="{row}">
            <div class="right">
              <span> {{ Number(row.代扣款).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="实发离退休费"
          width="120"
        >
          <template slot-scope="{row}">
            <div class="right">
              <span> {{ Number(row.实发离退休费).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,") }}</span>
            </div>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column
        label="人数（人）"
        align="center"
      >
        <el-table-column
          align="center"
          prop="小计"
          label="小计"
          width="120"
        />

        <el-table-column
          align="center"
          prop="在职"
          label="在职"
          width="120"
        />
        <el-table-column
          align="center"
          prop="离退休"
          label="离退休"
          width="120"
        />
      </el-table-column>
      <el-table-column
        align="center"
        prop="备注"
        label="备注"
        width="50"
      />
    </el-table>
    <pagination
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { attachmentPreservation } from '@/api/reportForm'
import { getAgencyBank } from '@/api/baseInfo'
import tableEmpty from '@/components/table/empty'
export default {
  components: {
    Pagination,
    tableEmpty
  },
  data() {
    return {
      agencyBankLists: [],
      list: [],
      listLoading: true,
      total: 0,
      listQuery: {
        page: 1,
        limit: 200,
        salaCardBank: '',
        salaryMonth: '',
        idenNo: ''
      }
    }
  },
  watch: {
    listQuery: {
      handler() {
        this.handleFilter()
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    this.initDict()
    this.getCurrenMonth()
    this.handleFilter()
  },
  methods: {
    initDict() {
      getAgencyBank().then(response => {
        this.agencyBankLists = Object.assign({}, response.data)
      })
    },
    // 查询
    handleFilter() {
      this.listQuery.page = 1
      // this.listQuery.limit = 10
      this.getList()
    },
    getList() {
      this.listLoading = true
      // const params = Object.assign({}, this.listQuery, this.formData)
      attachmentPreservation(this.listQuery)
        .then(response => {
          this.list = response.data.rows
          this.total = response.data.total
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    getCurrenMonth() {
      const date = new Date()
      const month = (date.getMonth() + 1).toString().padStart(2, '0')
      const year = date.getFullYear()
      this.listQuery.salaryMonth = year + '-' + month
    }
  }
}
</script>

<style scoped lang="scss">
.monthstyle {
  font-size: 14px;
  color: #606266;
}
.right{
  float: right;
}
</style>
